#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (auto &x : h) cin >> x;
  vector<vector<array<int, 2>>> dp(n, vector<array<int, 2>>(n));
  const int mod = 19650827;
  for (int l = n - 1; l >= 0; l --) {
    dp[l][l][0] = 1;
    for (int r = l + 1; r < n; r ++) {
      // [l + 1][r][0]  ->  [l][r][0]
      if (h[l] < h[l + 1]) dp[l][r][0] = (dp[l][r][0] + dp[l + 1][r][0]) % mod;
      // [l + 1][r][1]  ->  [l][r][0]
      if (h[l] < h[r]) dp[l][r][0] = (dp[l][r][0] + dp[l + 1][r][1]) % mod;
      // [l][r - 1][0]  ->  [l][r][1]
      if (h[r] > h[l]) dp[l][r][1] = (dp[l][r][1] + dp[l][r - 1][0]) % mod;
      // [l][r - 1][1] -> [l][r][1]
      if (h[r] > h[r - 1]) dp[l][r][1] = (dp[l][r][1] + dp[l][r - 1][1]) % mod;
    }
  }
  cout << (dp[0][n - 1][0] + dp[0][n - 1][1]) % mod << endl;
}